import instance from "@/utils/request";
import { Tag, Articles, UserReg, User_Rsp, ArticleDetail, CreateArticleInfo, SingleComment, AddCommentInfo, MultComments } from "@/model";

export function getTag(): Promise<{data: Tag}>{
    return instance({
        method: 'get',
        url: 'tags'
    })
}

export function getArticles(): Promise<{data: Articles}>{
    return instance({
        method: 'get',
        url: 'articles'
    })
}

export function getArticle(article_id:string): Promise<{data: ArticleDetail}>{
    return instance({
        method: 'get',
        url: `articles/${article_id}`
    })
}

export function createAricle(params:CreateArticleInfo): Promise<{data: ArticleDetail}>{
    return instance({
        method: 'post',
        url: 'articles',
        data: params
    })
}

export function update_article(params:CreateArticleInfo,article_id:string): Promise<{data: ArticleDetail}>{
    return instance({
        method: 'put',
        url: `articles/${article_id}`,
        data: params
    })
}

export function addcomments(params:AddCommentInfo,article_id:string): Promise<{data: SingleComment}>{
    return instance({
        method: 'post',
        url: `articles/${article_id}/comments`,
        data: params
    })
}

export function getcomments(article_id:string): Promise<{data: MultComments}>{
    return instance({
        method: 'get',
        url: `articles/${article_id}/comments`
    })
}

export function register(params:UserReg): Promise<{data: User_Rsp}>{
    return instance({
        method: 'post',
        url: 'users',
        data: params
    })
}

export function login(params:UserReg): Promise<{data: User_Rsp}>{
    return instance({
        method: 'post',
        url: 'users/login',
        data: params
    })   
}